package com.spring.demo.spring_boot;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.messaging.Source;

import com.spring.demo.spring_boot.mapper.UserMapper;

/**
 * 
 * @author 王辉阳
 * @date 2017年8月2日 上午9:50:58
 * @description @EnableAutoConfiguration 注解表示会隐式定义一个search
 *              package，建议@SpringBootApplication注解的类总放在根目录下
 * 
 *              好处：
 *              <p>
 *              1，寻找包下所有@Entity的类
 *              2， @ComponentScan可不指定basePackage会自动scan到包下的组件( @Service, @RestController等)
 *              </p>
 */
@EnableBinding(Source.class)
@SpringBootApplication
public class DBApplication implements CommandLineRunner {
	private static final Logger logger = LogManager.getLogger(DBApplication.class);
	private final UserMapper userMapper;

	public DBApplication(UserMapper userMapper) {
		this.userMapper = userMapper;
	}

	public static void main(String[] args) {
		SpringApplication.run(DBApplication.class, args);
	}

	@Override
	public void run(String... args) throws Exception {
		logger.debug("run执行方法");
		System.out.println(this.userMapper.findByName("wanghuiyang"));
		logger.debug("查询结束");
	}

}
